package com.gitee.huxing.clone;

/**
 * @Description: 浅拷贝
 * @ProjectName: AlgorithmicPactice
 * @Package: com.gitee.huxing.clone
 * @ClassName: ShallowCopy
 * @Author: huxing
 * @DateTime: 2022-04-11 5:02 PM
 */
public class ShallowCopy {

    public static void main(String[] args) throws CloneNotSupportedException{
        Teacher teacher = new Teacher("huxing", 28);
        Student student1 = new Student();
        student1.setAge(18);
        student1.setName("edgar");
        student1.setTeacher(teacher);

        Student student2 = (Student) student1.clone();
        System.out.println("-------------拷贝后-------------");
        System.out.println(student2.getName());
        System.out.println(student2.getAge());
        System.out.println(student2.getTeacher().getName());
        System.out.println(student2.getTeacher().getAge());

        System.out.println("-------------修改老师的信息后-------------");
        // 修改老师的信息
        teacher.setName("jack");
        System.out.println("student1的teacher为： " + student1.getTeacher().getName());
        System.out.println("student2的teacher为： " + student2.getTeacher().getName());
    }
}
